package com.demo;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.stream.IntStream;

import org.junit.Test;

public class LambdaTest {

	
	@Test
	public void test4(){
		Collection<String> books=new HashSet<>();
		books.add("aaaaa");
		books.add("bbb");
		books.add("cc");
		books.add("ddddddd");
	    //统计书名长度大于5的图书数量
		System.out.println(books.stream().filter(ele-> ele.length()>=5).count());
	}
	@Test
	public void test3(){
		IntStream is = IntStream.builder().add(20).add(13).add(-2).add(18).build();
		//下面调用聚集方法的代码，每次只能执行一行
		/*
		System.out.println("is所有元素的最大值:"+is.max().getAsInt());
		System.out.println("is所有元素的最小值:"+is.min().getAsInt());
		System.out.println("is所有元素的总和:"+is.sum());
		System.out.println("is所有元素的总数:"+is.count());
		System.out.println("is所有元素的平均值:"+is.average());
		*/
	}
	
	@Test
	public void test2(){
		Collection<String> books=new HashSet<>();
		books.add("aaaaa");
		books.add("bbb");
		books.add("cc");
		books.add("ddddddd");
	    books.removeIf(ele -> ele.length() <5);
	    System.out.println(books);
	}
	
	@Test
	public void test1(){
		Collection<String> books=new HashSet<>();
		books.add("a");
		books.add("b");
		books.add("c");
		books.add("d");
		books.forEach(obj -> System.out.println("迭代集合元素:"+obj));
		Iterator<String> it = books.iterator();
		it.forEachRemaining(obj->System.out.println("Iterator迭代集合元素:"+obj));
	}
}
